package com.smallkingson.ylib.net.http.bean;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public abstract class YUrl {

	protected TreeMap<String, String> params;

	protected String dir;

	public abstract String getNoAuthUrl();

	public abstract String getUrl();



	/**
	 * 添加参数
	 * @param key
	 * @param value
	 * @return
	 */
	public YUrl p(String key, String value) {

		params.put(key, value);

		return this;
	}
	public YUrl(String dir) {
		this.dir = dir;
		params = new TreeMap<String, String>();
	}

	/**
	 * 
	 * @return "key=value & key=value"
	 */
	public String getParamStr() {

		StringBuffer paramsStringBuffer = new StringBuffer();

		for (String key : params.keySet()) {

			String value = params.get(key);

			paramsStringBuffer.append(key).append("=").append(value)
					.append("&");
		}

		if(paramsStringBuffer.length()==0){
			return paramsStringBuffer.toString();
		}
		return paramsStringBuffer.substring(0, paramsStringBuffer.length() - 1);
	}
	@Override
	public String toString() {
		return "未加密过:"+getNoAuthUrl()+" , 加密后:"+getUrl();
	}
}